package com.fzrskj.cloud.free.core.enums;

/**
 * CloudHostStatusEnum.
 *
 * @author zj.
 *         Created on 2018/9/17 0017.
 */
public enum HyperVStatusEnum {
    /**
     * 创建中.
     */
    CREATING("Starting", "创建中", 201),
    STOPPED2("Stopped", "已停止", 1),
    RUNNING("Running", "运行中", 2),
    STOPPED("Stopped", "已停止", 3),
    SAVED("Saved", "已保存", 99),
    EXPIRE("Expire", "到期", 6),
    STARTING("Starting", "启动中", 202),
    STOPPING("Stopping", "停止中", 301),
    RESTARTING("Restarting", "重启中", 11),
    PAUSED("Paused", "暂停", 9);

    /**
     * 状态.
     */
    private String status;

    /**
     * 状态名称.
     */
    private String name;

    /**
     * 实际对应状态码.
     */
    private Integer realState;

    /**
     * 构造体.
     * @param status status.
     * @param name name.
     * @param realState hyper-v really state.
     */
    HyperVStatusEnum(String status, String name, Integer realState) {
        this.status = status;
        this.name = name;
        this.realState = realState;
    }

    /**
     * 获取状态.
     * @return String.
     */
    public String getStatus() {
        return this.status;
    }

    /**
     * 获取状态名称.
     * @return String.
     */
    public String getName() {
        return this.name;
    }

    /**
     * 获取状态
     * @return
     */
    public Integer getRealState() {
        return this.realState;
    }

    /**
     * 通过表状态获取hyper-v对应数字状态.
     * @param status
     * @return
     */
    public static Integer getRealState(String status) {
        for (HyperVStatusEnum hyperVStatusEnum : HyperVStatusEnum.values()) {
            if (status.equals(hyperVStatusEnum.getStatus())) {
                return hyperVStatusEnum.getRealState();
            }
        }
        return HyperVStatusEnum.RUNNING.getRealState();
    }

    /**
     * 通过hyper-v数字状态获取状态枚举.
     * @param realState
     * @return
     */
    public static HyperVStatusEnum getHyperVStatusEnum(Integer realState) {
        for (HyperVStatusEnum hyperVStatusEnum : HyperVStatusEnum.values()) {
            if (hyperVStatusEnum.getRealState().equals(realState)) {
                return hyperVStatusEnum;
            }
        }
        return HyperVStatusEnum.RUNNING;
    }
}
